class PlayBoy {
  constructor(name) {
    this.name = name;
    this.taskList = [];

    setTimeout(() => {
      this.next();
    }, 0);
  }

  sayHi() {
    this.taskList.push(() => {
      console.log(`我叫${this.name}`);
      this.next();
    });

    //   链式调用
    return this;
  }
  sleep(time) {
    this.taskList.push(() => {
      setTimeout(() => {
        console.log(`睡觉${time}秒。。。`);
        this.next();
      }, time);
    });
    return this;
  }

  game(gameName) {
    this.taskList.push(() => {
      console.log(`我在玩游戏${gameName}`);
      this.next();
    });
    return this;
  }

  next() {
    const nextFun = this.taskList.shift();
    nextFun && nextFun();
  }
}

const wn = new PlayBoy("ck");
wn.sayHi().game("basketball").sleep(4000).game("vollayball");
